import amesu from "../model/bot/amesu";
import browser, { tempDir } from "../model/browser/browser";
import server from "../model/client/server";

export class style_default {
    line: string[] = []
    title: string
    _help: string = undefined;
    constructor() {

    }
    setTitle(str: string, icon = '💡') {
        switch (str.length) {
            case 4:
                this.title = `┏┄══${icon}${str}══━┄\n`
                break;
            case 3:
                this.title = `┏┄═══${icon}${str}═━┄\n`
                break;
            default:
                this.title = `┏┄══${icon}${str}═━┄\n`
                break;
        }
    }
    setline_Title(str: string, icon: string) {
        switch (str.length) {
            case 5:
                this.line.push(`╞═══${icon}${str}═━┄`);
                break;
            case 4:
                this.line.push(`╞════${icon}${str}═━┄`);
                break;
            case 3:
                this.line.push(`╞════${icon}${str}══━┄`);
                break;
            default:
                this.line.push(`╞══${str}═━┄`);
                break;
        }
    }
    addLine(str: string) {
        this.line.push(str);
    }
    async addOne() {
        let req = await server.api('openApi/OneMore', {});
        if (!req) {
            return;
        }
        this.addLine(`「${req.str}」`);
    }
    help(str: string) {
        this._help = str;
    }
    end(end: boolean = true) {
        let str = ``;
        if (this.title) {
            str += this.title;
        }
        for (let i = 0; i < this.line.length; i++) {
            const s = this.line[i];
            str += `${s}\n`;
        }
        if (this._help) {
            str += `💡相关指令[${this._help}]\n`
        }
        if (end) {
            str += `┗━━━━━━━━━━━━┄`
        }
        return str;
    }
    toimg(id:string) {
        let list = this.end().split('\n');
        browser.render(tempDir.通用文字, {
            list: list
        }).then((png) => {
            amesu.sendLocaImage(id, png);
        });
    }
    img(){
        return new Promise((resolve, reject) => {
            let list = this.end().split('\n');
            browser.render(tempDir.通用文字, {
                list: list
            }).then((png) => {
                resolve(png);
            });
        });
    }
}